public class Demo7 {
	private static int count=0;

	/**
	 * synchronized可以修饰实例方法，类似于修饰synchronized(this)
	 * 如果修饰于静态的方法，相当于给类对象加锁了
	 * sychronized (Counter.class)
	 */
	synchronized public static void increase() {
		count++;
	}
	public static void main(String[] args) throws InterruptedException {
		Object locker =new Object();
		Thread t=new Thread(()->{
			for(int i =0;i<50000;i++) {
				increase();
			}
		});
		Thread t1=new Thread(()->{
			for(int i =0;i<50000;i++) {
				increase();
			}
		});
		t.start();
		t1.start();
		t.join();
		t1.join();
		System.out.println(count);
	}
}
